function [out]=OptFsum(x)
% x = Fsum

% global theta numpatches Dii Bij_initial max_age age_mature...
%     age_legal  Wij delta pr max_simulation_length Fsum  hide0_show1_figures...
%      K beta_i_initial alpha1 Bi_legal_fish

global theta  numpatches Dii   domain_suit_hab max_age age_mature...
    age_legal  Wij Rmax alpha1 delta Kvirgin  pr max_simulation_length ...
       Fsum  hide0_show1_figures K Bi_legal_fish  beta_i_initial ...
       Bij_initial TargetBiomass CRgoal theta_percent...
       FleetProfit_Fsum_opt Payoff_Conservation_EF_alpha MPA_locs...
       NPVon discounted_value_iy discounted_value_ijy

Fsum=x;
MOPmodel2

Profit_y_OptFsum=sum(Profit_iy,1);
out=-sum(Profit_y_OptFsum(end)); %total profit at equilibrium